package cn.ibizlab.odoo.core.odoo_hr.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard;
import cn.ibizlab.odoo.core.odoo_hr.domain.Hr_expense_sheet_register_payment_wizard;
import cn.ibizlab.odoo.core.odoo_hr.filter.Hr_expense_sheet_register_payment_wizardSearchContext;
import cn.ibizlab.odoo.core.odoo_hr.service.IHr_expense_sheet_register_payment_wizardService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[费用登记付款向导] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Hr_expense_sheet_register_payment_wizardServiceImpl implements IHr_expense_sheet_register_payment_wizardService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ihr_expense_sheet_register_payment_wizardClientService hr_expense_sheet_register_payment_wizardClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //hr_expense_sheet_register_payment_wizardClientService.removeBatch(hr_expense_sheet_register_payment_wizards) ;

    }

    @Override
    public boolean create(Hr_expense_sheet_register_payment_wizard hr_expense_sheet_register_payment_wizard) {
        boolean bOk = false ;
        Ihr_expense_sheet_register_payment_wizard clientModel = this.convert2Model(hr_expense_sheet_register_payment_wizard,null);
        hr_expense_sheet_register_payment_wizardClientService.create(clientModel) ;
        this.convert2Domain(clientModel,hr_expense_sheet_register_payment_wizard);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void updateBatch(List<Hr_expense_sheet_register_payment_wizard> hr_expense_sheet_register_payment_wizards, int batchSize) {

        //hr_expense_sheet_register_payment_wizardClientService.updateBatch(hr_expense_sheet_register_payment_wizards,batchSize) ;

    }

    @Override
    public Hr_expense_sheet_register_payment_wizard get(Integer id) {
        Ihr_expense_sheet_register_payment_wizard clientModel = hr_expense_sheet_register_payment_wizardClientService.createModel();
        clientModel.setId(id);
        hr_expense_sheet_register_payment_wizardClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Hr_expense_sheet_register_payment_wizard get(Hr_expense_sheet_register_payment_wizard hr_expense_sheet_register_payment_wizard) {
        Hr_expense_sheet_register_payment_wizard rethr_expense_sheet_register_payment_wizard = this.get(hr_expense_sheet_register_payment_wizard.getId()) ;
    	BeanCopier copier=BeanCopier.create(rethr_expense_sheet_register_payment_wizard.getClass(), hr_expense_sheet_register_payment_wizard.getClass(), false);
        copier.copy(rethr_expense_sheet_register_payment_wizard, hr_expense_sheet_register_payment_wizard, null);
        return hr_expense_sheet_register_payment_wizard ;
    }

    @Override
    public boolean update(Hr_expense_sheet_register_payment_wizard hr_expense_sheet_register_payment_wizard) {
        boolean bOk = false ;
        Ihr_expense_sheet_register_payment_wizard clientModel = this.convert2Model(hr_expense_sheet_register_payment_wizard,null);
        hr_expense_sheet_register_payment_wizardClientService.update(clientModel) ;
        this.convert2Domain(clientModel,hr_expense_sheet_register_payment_wizard) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ihr_expense_sheet_register_payment_wizard clientModel = hr_expense_sheet_register_payment_wizardClientService.createModel();
        clientModel.setId(id);
        hr_expense_sheet_register_payment_wizardClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Hr_expense_sheet_register_payment_wizard> hr_expense_sheet_register_payment_wizards, int batchSize) {

                        //hr_expense_sheet_register_payment_wizardClientService.createBatch(hr_expense_sheet_register_payment_wizards,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> searchDefault(Hr_expense_sheet_register_payment_wizardSearchContext context) {
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据日记账查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> selectByOdoo_journal(Integer id){
        Hr_expense_sheet_register_payment_wizardSearchContext context = new Hr_expense_sheet_register_payment_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据付款方法查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> selectByOdoo_payment_method(Integer id){
        Hr_expense_sheet_register_payment_wizardSearchContext context = new Hr_expense_sheet_register_payment_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据币种查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> selectByOdoo_currency(Integer id){
        Hr_expense_sheet_register_payment_wizardSearchContext context = new Hr_expense_sheet_register_payment_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据银行账户查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> selectByOdoo_partner_bank_account(Integer id){
        Hr_expense_sheet_register_payment_wizardSearchContext context = new Hr_expense_sheet_register_payment_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> selectByOdoo_partner(Integer id){
        Hr_expense_sheet_register_payment_wizardSearchContext context = new Hr_expense_sheet_register_payment_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> selectByOdoo_create(Integer id){
        Hr_expense_sheet_register_payment_wizardSearchContext context = new Hr_expense_sheet_register_payment_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Hr_expense_sheet_register_payment_wizard> selectByOdoo_write(Integer id){
        Hr_expense_sheet_register_payment_wizardSearchContext context = new Hr_expense_sheet_register_payment_wizardSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_expense_sheet_register_payment_wizard> list = new ArrayList<Hr_expense_sheet_register_payment_wizard>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard> clientModelList = hr_expense_sheet_register_payment_wizardClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_expense_sheet_register_payment_wizard clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_expense_sheet_register_payment_wizard>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ihr_expense_sheet_register_payment_wizard convert2Model(Hr_expense_sheet_register_payment_wizard domain , Ihr_expense_sheet_register_payment_wizard model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = hr_expense_sheet_register_payment_wizardClientService.createModel() ;
        }

         if(domain.getAmountDirtyFlag())
            model.setAmount(domain.getAmount());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCommunicationDirtyFlag())
            model.setCommunication(domain.getCommunication());
         if(domain.getHide_payment_methodDirtyFlag())
            model.setHide_payment_method(domain.getHide_payment_method());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getShow_partner_bank_accountDirtyFlag())
            model.setShow_partner_bank_account(domain.getShow_partner_bank_account());
         if(domain.getPayment_dateDirtyFlag())
            model.setPayment_date(domain.getPayment_date());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getJournal_id_textDirtyFlag())
            model.setJournal_id_text(domain.getJournal_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getPayment_method_id_textDirtyFlag())
            model.setPayment_method_id_text(domain.getPayment_method_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getCurrency_id_textDirtyFlag())
            model.setCurrency_id_text(domain.getCurrency_id_text());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getPayment_method_idDirtyFlag())
            model.setPayment_method_id(domain.getPayment_method_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getPartner_bank_account_idDirtyFlag())
            model.setPartner_bank_account_id(domain.getPartner_bank_account_id());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
        return model ;
    }

    public Hr_expense_sheet_register_payment_wizard convert2Domain( Ihr_expense_sheet_register_payment_wizard model ,Hr_expense_sheet_register_payment_wizard domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Hr_expense_sheet_register_payment_wizard();
        }

        if(model.getAmountDirtyFlag())
            domain.setAmount(model.getAmount());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCommunicationDirtyFlag())
            domain.setCommunication(model.getCommunication());
        if(model.getHide_payment_methodDirtyFlag())
            domain.setHide_payment_method(model.getHide_payment_method());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getShow_partner_bank_accountDirtyFlag())
            domain.setShow_partner_bank_account(model.getShow_partner_bank_account());
        if(model.getPayment_dateDirtyFlag())
            domain.setPayment_date(model.getPayment_date());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getJournal_id_textDirtyFlag())
            domain.setJournal_id_text(model.getJournal_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getPayment_method_id_textDirtyFlag())
            domain.setPayment_method_id_text(model.getPayment_method_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getCurrency_id_textDirtyFlag())
            domain.setCurrency_id_text(model.getCurrency_id_text());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getPayment_method_idDirtyFlag())
            domain.setPayment_method_id(model.getPayment_method_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getPartner_bank_account_idDirtyFlag())
            domain.setPartner_bank_account_id(model.getPartner_bank_account_id());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        return domain ;
    }


}
